package trlygjj.tanruiliyigenjinjin.web.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.*;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.BigClientQueryObject;
import trlygjj.tanruiliyigenjinjin.service.*;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;
import trlygjj.tanruiliyigenjinjin.util.PermissionName;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("bigClient")
public class BigClientController {

    @Autowired
    private IBigClientService bigClientService;
    @Autowired
    private IDataDictionaryService dataDictionaryService;
    @Autowired
    private ILinkmanService linkmanService;
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private ICurriculumSeriesService curriculumSeriesService;
    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
    @PermissionName("大客户首页")
    @RequiresPermissions("bigClient:index")
    @RequestMapping("")
    public String index(){
        return "bigClient/list";
    }

    /**
     * 具有分页和高级查询
     * @return
     */
    @PermissionName("大客户列表数据")
    @RequiresPermissions("bigClient:list")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(BigClientQueryObject qo){
        PageResult result = bigClientService.query(qo);
        return result;
    }

    /**
     * 查询全部
     * @return
     */
    @PermissionName("大客户查选全部")
    @RequiresPermissions("bigClient:listAll")
    @RequestMapping("listAll")
    @ResponseBody
    public List<BigClient> listAll(){
        return bigClientService.selectAll();
    }

    /**
     * 删除
     * @param bigClientId 要删除的员工对象id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @PermissionName("大客户删除")
    @RequiresPermissions("bigClient:delete")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long bigClientId){
        JsonResult result = new JsonResult();
        try{
            bigClientService.deleteByPrimaryKey(bigClientId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     *更新
     * @param bigClient 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @PermissionName("大客户跟新")
    @RequiresPermissions("bigClient:update")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(BigClient bigClient){
        JsonResult result = new JsonResult();
        try{
            bigClientService.updateByPrimaryKey(bigClient);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 保存
     * @param bigClient 要保存的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @PermissionName("大客户保存")
    @RequiresPermissions("bigClient:save")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(BigClient bigClient){
        JsonResult result = new JsonResult();
        try{
            bigClientService.insert(bigClient);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }
    @PermissionName("大客户更新跟进状态")
    @RequiresPermissions("bigClient:updateFollowState")
    @RequestMapping("updateFollowState")
    @ResponseBody
    /**
     * 更新跟进状态
     */
    public JsonResult updateFollowState(BigClient bigClient){
        JsonResult result = new JsonResult();
        try{
            bigClientService.updateFollowState(bigClient);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }
    @PermissionName("更新客户状态")
    @RequiresPermissions("bigClient:updateContractState")
    @RequestMapping("updateContractState")
    @ResponseBody()
    /**
     * 更新客户状态
     */
    public JsonResult updateContractState(BigClient bigClient){
        JsonResult result = new JsonResult();
        try{
            bigClientService.updateContractState(bigClient);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 通过sn,在字典获取大客户的重要程度
     */
    @PermissionName("获取重要程度")
    @RequiresPermissions("bigClient:getImportantBySn")
    @RequestMapping("getImportantBySn")
    @ResponseBody
    public List<DataDictionary> getImportantBySn(DataDictionary sn){
       return dataDictionaryService.getImportantBySn(sn);
    }
    /**
     * 通过sn,在字典获取大客户的意向程度
     */
    @PermissionName("获取意向程度")
    @RequiresPermissions("bigClient:getIntentionBySn")
    @RequestMapping("getIntentionBySn")
    @ResponseBody
    public List<DataDictionary> getIntentionBySn(DataDictionary sn){
       return dataDictionaryService.getIntentionBySn(sn);
    }
    /**
     * 在CurriculumSeries获取大客户的意向学科
     */
    @PermissionName("获取意向学科")
    @RequiresPermissions("bigClient:getIntentionSubject")
    @RequestMapping("getIntentionSubject")
    @ResponseBody
    public List<CurriculumSeries> getIntentionSubject(){
       return curriculumSeriesService.selectAll();
    }
    /**
     * 通过sn,在字典获取大客户的意向校区
     */
    @PermissionName("获取意向校区")
    @RequiresPermissions("bigClient:getIntentionDistrictBySn")
    @RequestMapping("getIntentionDistrictBySn")
    @ResponseBody
    public List<DataDictionary> getIntentionDistrictBySn(DataDictionary sn){
       return dataDictionaryService.getIntentionDistrictBySn(sn);
    }
    /**
     * 通过sn,在字典获取大客户的规定学历
     */
    @PermissionName("获取规定学历")
    @RequiresPermissions("bigClient:getEducationBySn")
    @RequestMapping("getEducationBySn")
    @ResponseBody
    public List<DataDictionary> getEducationBySn(DataDictionary sn){
       return dataDictionaryService.getEducationBySn(sn);
    }
    /**
     * 通过sn,在字典获取大客户的学校体制
     */
    @PermissionName("获取学校体制")
    @RequiresPermissions("bigClient:getSchoolSystemBySn")
    @RequestMapping("getSchoolSystemBySn")
    @ResponseBody
    public List<DataDictionary> getSchoolSystemBySn(DataDictionary sn){
       return dataDictionaryService.getSchoolSystemBySn(sn);
    }

    /**
     * 获取学校名字
     */
    @PermissionName("获取学校名字")
    @RequiresPermissions("bigClient:getShcoolName")
    @RequestMapping("getShcoolName")
    @ResponseBody
    public List<Linkman> getShcoolName(){
       return linkmanService.selectAll();
    }
    /**
    /**
     * 获取学校联系人
     */
    @PermissionName("获取学校联系人")
    @RequiresPermissions("bigClient:getLinkman")
    @RequestMapping("getLinkman")
    @ResponseBody
    public List<Linkman> getLinkman(){
       return linkmanService.selectAll();
    }
    /**
     * 获取营销人员
     */
    @PermissionName("获取营销人员")
    @RequiresPermissions("bigClient:getMarketer")
    @RequestMapping("getMarketer")
    @ResponseBody
    public List<Employee> getMarketer(){
       return employeeService.selectAll();
    }
    /**
     * 获取跟进人员
     */
    @PermissionName("获取跟进人员")
    @RequiresPermissions("bigClient:getMerchandiser")
    @RequestMapping("getMerchandiser")
    @ResponseBody
    public List<Employee> getMerchandiser(){
       return employeeService.selectAll();
    }
}
